package demo

import (
	"encoding/json"
	"fmt"
)

func SubQuery() {
	Init()
	var advanceds []Advanced
	// DB.Debug().Raw("SELECT * FROM advanceds WHERE age > (SELECT AVG(age) FROM advanceds)").Find(&advanceds)

	//？一定要用(?) 不然会报错
	DB.Debug().Where("age > (?)", DB.Model(Advanced{}).Select("AVG(age)")).Find(&advanceds)

	json, _ := json.Marshal(advanceds)
	fmt.Println(string(json))
}
